import router from "./router";
import { delCookie, getCookie } from "@/utils/mainCookie";
router.beforeEach(async (to, from, next) => {
  var authorization = getCookie("authorization");
  var Islogin = getCookie("Islogin");
  if (to.path === "/login") {
    if (Islogin != "") {
      next({
        path: from.fullPath
      });
      if (from.meta.title) {
        document.title = from.meta.title;
      }
    } else {
      if (to.meta.title) {
        document.title = to.meta.title;
      }
      sessionStorage.clear();
      localStorage.clear();
      delCookie("authorization");
      delCookie("appId");
      delCookie("Islogin");
      next();
    }
  } else {
    if (to.meta.title) {
      document.title = to.meta.title;
    }
    if (to.meta.requireAuth && (!authorization || !Islogin)) {
      next({
        path: "/login"
      });
    } else {
      next();
    }
  }
});
